<?php

namespace slinks\extensions\action\interceptor;

use slinks\extensions\action\core\IActionInvocation;

/**
 * Injects the action into the paramater list so it can be used as the action.
 * 
 * @author Navid Mitchell
 *
 */
class ActionInjectingInterceptor implements IActionInterceptor {

    /**
     * Allows the Interceptor to do some processing on the request before and/or after the rest of the processing of the
     * request by the IActionInvocation or to short-circuit the processing and just return a String return code.
     *
     * @param IActionInvocation invocation the action invocation
     * @see IActionInterceptor::intercept(IActionInvocation $invocation)
     */
    public function intercept(IActionInvocation $invocation) {

        // LOOK: should we check if a parameter named action already exists

        $invocation->getActionContext()->getValueStack()->set('action', $invocation->getActionProxy()->getObject());

        $invocation->invoke();
    }

}